/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package biofilter.filters;

import biofilter.records.*;
import biofilter.sources.RecordsFile;
import biofilter.util.ArrayUtil;
import java.util.Vector;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;


/**
 * This test is essentially the same as the RecordsFile2BowtieRecordTest... because RecordsFile2MappedPosition is a more general class.
 * We first want to verify that it works as RecordsFile2BowtieRecord works.
 * @author Daniel Quest
 * @date   Thu Feb 25 2010
 */
public class RecordsFile2MappedPositionTest {

    public RecordsFile2MappedPositionTest() {
    }

    private static RecordsFile2MappedPosition rf2mp = null;
    private static FileNameRecord r1 = null;
    private static FileNameRecord r2 = null;
    private static RecordsFile bowtieRecords = null;

    @BeforeClass
    public static void setUpClass() throws Exception {
        System.out.println("SetUpClass ");
        r1 = new FileNameRecord();
        r1.set("./test/testdata/simple.bowtie");
        r2 = new FileNameRecord();
        r2.set("./test/testdata/realshort.bowtie");
        Vector<Record> v = new Vector<Record>();
        v.add(r1);
        v.add(r2);
        ArrayUtil aute = new ArrayUtil();
        Record [] r = aute.toArray(v);
        aute.printArray(r);
        bowtieRecords = new RecordsFile(r, "biofilter.records.FileNameRecord");
        rf2mp = new RecordsFile2MappedPosition();
        rf2mp.setMappedPositionType("biofilter.records.BowtieRecord");
        rf2mp.setSource(bowtieRecords);
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    /**
     * Test of setMappedPositionType method, of class RecordsFile2MappedPosition.
     */
    @Test
    public void testSetMappedPositionType() {
        System.out.println("setGetMappedPositionType");
        String mappedPositionType = "biofilter.records.BowtieRecord";
        RecordsFile2MappedPosition instance = new RecordsFile2MappedPosition();
        instance.setMappedPositionType(mappedPositionType);
        assertEquals(mappedPositionType, instance.getMappedPositionType());
    }


    @Test
    public void testTransformRecord() throws Exception {
        System.out.println("transformRecord");
        BowTieRecord expResult = new BowTieRecord();
        String line = "HWI-EAS127_3_4_1_774_879\t-\tctg93\t4\tAAN\tIII\t1\t38:G>N\n";
        expResult.set(line);
        FileNameRecord r = new FileNameRecord(line);
        BowTieRecord result = (BowTieRecord) rf2mp.transformRecord(r);
        assertEquals(expResult.get(), result.get());
    }

    @Test
    public void testGetRecord() throws Exception {
        System.out.println("getRecord");
        String line = "HWI-EAS127_3_4_1_774_879\t-\tctg93\t4\tAAN\tIII\t1\t38:G>N";
        BowTieRecord result = (BowTieRecord) rf2mp.getRecord();
        String r1 = line;
        //System.err.println(result.get());
        //result.set(line);
        //System.err.println(result.get());
        assertEquals(line, result.get());
        //now lets test going off of this file and on to the next!
        //HWI-EAS127_3_4_1_774_879	-	ctg93	4	AAN	III	1	38:G>N
        result = (BowTieRecord) rf2mp.getRecord();//HWI-EAS127_3_4_1_774_879	-	ctg94	3	AAN	III	1	38:G>N
        result = (BowTieRecord) rf2mp.getRecord();//HWI-EAS127_3_4_1_774_879	-	ctg95	6	AAT	III	0	38:G>N
        String res = "HWI-EAS127_3_4_1_774_879\t-\tctg95\t6\tAAT\tIII\t0";
        assertEquals(res, result.get());
        result = (BowTieRecord) rf2mp.getRecord();//HWI-EAS127_3_4_1_774_879	+	ctg95	1	GTT	III	0	38:C>N
        result = (BowTieRecord) rf2mp.getRecord();//HWI-EAS127_3_4_1_774_879	+	ctg95	2	NAG	III	1	38:C>N
        result = (BowTieRecord) rf2mp.getRecord();//HWI-EAS127_3_4_1_774_879	+	ctg95	3	GAG	III	0	38:C>N
        result = (BowTieRecord) rf2mp.getRecord();//HWI-EAS127_3_4_1_36_5261	-	ctg95	7	TCA	III	0	38:G>N
        result = (BowTieRecord) rf2mp.getRecord();//HWI-EAS127_3_4_1_36_5261	+	ctg94	1	TCA	III	0	38:G>N
        result = (BowTieRecord) rf2mp.getRecord();//HWI-EAS127_3_4_1_36_5261	-	ctg93	4	TCA	III	0	38:G>N
        result = (BowTieRecord) rf2mp.getRecord();//HWI-EAS127_3_4_1_36_5261	+	ctg95	3	TTT	III	0	38:C>N
        result = (BowTieRecord) rf2mp.getRecord();//HWI-EAS127_3_4_1_36_5265	+	ctg95	3	TTT	III	0	38:C>N
        result = (BowTieRecord) rf2mp.getRecord();
        //System.err.println(result.get());
        String line2 = "HWI-EAS128_2_6_1_237_354\t+\tgi|116688024|ref|NC_008542.1| Burkholderia cenocepacia HI2424 chromosome 1, complete sequence\t377752\tGATACCCTGGTAGTCCACGCCCTAAACGATGTCAACTAG\tIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII\t1";
        //System.err.println(line2);
        assertEquals(line2, result.get());

    }

}